/*
	Aiviki Javascript library
	
	http://www.aiviki.com/ajs

	By RolandShiue
*/

var aiviki=	{
	version:"0.3.0",
	author:"RolandShiue",
	power:"aiviki",
	debug:false,
	bind:function(__method,object){return function(){return __method.apply(object, arguments);}}
	}
aiviki.Class =
	{
	create: function(_name)
		{
		return function()
			{
			this.extend =function(source)
				{
				if(this==source&&DEBUG)
					{
					//不能繼承自己
					return;
					}
				this.parentObject=source;
				for (property in source)
					{
					if(this[property]==null)
						this[property] = source[property];
					}
				}
			this.parentObject=null;

			this.toNameSpace=function()
				{
				if(this.parentObject!=null)
					{
					var ny = [];
					var obj = this;
					while(obj.parentObject!=null)
						{
						ny.push(obj.ClassId);
						obj=obj.parentObject;
						}
					ny.push(obj.ClassId);
					}
				return ny;
				}
			this.isSubClass=function(subObj)
				{
				if(this.ClassId == subObj.ClassId)return true;
				if(subObj.parentObject!=null)
					{
					var obj = subObj;
					while(obj.parentObject!=null)
						{
						if(this.ClassId == obj.ClassId)return true;
						obj=obj.parentObject;
						}
						if(this.ClassId == obj.ClassId)return true;
					}
				return false;
				}
			this.ClassId = _name;
			this.equal=function(obj)
				{
				if(this.ClassId == obj.ClassId)return true;
				return false;
				}
			this.init.apply(this, arguments);
			}
		}
	}


aiviki.packages = function()
{
	var root=window.location.href.substring(0,window.location.href.lastIndexOf("/")+1);
	var cp = new Array();
	var findClassPath = function(_cp){for(var i=0;i<cp.length;i++){if(cp[i]==_cp)return true;}return false;};
	var _debug=true;
	var axJs=function(_path)
	{
	var _xr;
	if(window.XMLHttpRequest)
		{
	    _xr=new XMLHttpRequest();
		}
	else if(window.ActiveXObject)
		{
	  _xr= new ActiveXObject('Microsoft.XMLHTTP')
		}
		_xr.open("GET",_path,false);
		try
		{
		_xr.send(null);
		}
		catch (failed)
		{
			if(_debug)
				alert("JS Load Error:"+_path);
			return false;
		}
		eval(_xr.responseText);
		return true;
	};
	return{
	imports:function(_cp)
		{
		if(findClassPath(_cp))return;
		__cp = _cp.replace(/\./g,"/")+".js";
		if(axJs(root+__cp))
			{
			cp[cp.length]=_cp;
			return true;
			}else{
			if(_debug)
				alert("Package Erro:"+_cp);
			return false;
			}

		},
	packagePath:function(path)
		{
		root+=path+"/"
		},
	};}();
$import =aiviki.packages.imports;
$jspath =aiviki.packages.packagePath;
function $bc(className)
	{
	var nArray =[];
	
	var tags=document.all? document.all : document.getElementsByTagName("*");
	for(i=0; i<tags.length; i++){
		if(tags[i].className==className)
			{
			nArray.push(tags[i]);
			}
		}
	return nArray;
	}

function $bi(idName) 
	{
	return document.getElementById(idName);
	}

function $bon(oo,ne)
	{
	var lg = oo.childNodes.length;
	var nArray =[];

	for(i=0;i<lg;i++)
		{
		if(oo.childNodes[i].tagName == ne)
			{
			nArray.push(oo.childNodes[i]);
			}else{
			if(oo.childNodes[i].length>=1)
				{
				alert(oo.childNodes[i].childNodes[0].tagName);
				}
			}
		}
	return nArray;
	}

//修正
var isIE = (window.navigator.userAgent.indexOf("MSIE")> 0);  
if(!isIE)
	{   
  HTMLElement.prototype.__defineGetter__("innerText",function () { return(this.textContent); });   
  HTMLElement.prototype.__defineSetter__("innerText",function (txt) { this.textContent = txt; });
	Event.prototype.__defineGetter__("srcElement",function(){var node=null;node = this.target;while (node && node.nodeType != 1){node = node.parentNode;}return node;});
	}

